package IteratorAndComposite.IteratorInterfacesImpl;

import IteratorAndComposite.entry.MenuItem;

import java.util.Calendar;
import java.util.Iterator;

/**
 * @Author: pengzx
 * @Description:
 * @Date: 17:54 2017/9/21
 * @Modified by: 1.0
 */
public class AlternatingDinerMenuIterator implements Iterator {
    MenuItem[] menuItems;
    int position ;

    public AlternatingDinerMenuIterator(MenuItem[] menuItems)
    {
        this.menuItems = menuItems;
        Calendar rightNow = Calendar.getInstance();
        position = rightNow.get(Calendar.DAY_OF_WEEK) % 2;
    }

    @Override
    public boolean hasNext()
    {
        if(position>=menuItems.length || menuItems[position] == null){
            return false;
        }else{
            return true;
        }
    }

    @Override
    public Object next()
    {
        MenuItem menuItem = menuItems[position];
        position = position+2;
        return menuItem;
    }

    @Override
    public void remove()
    {
        throw new UnsupportedOperationException("没有移除方法...");
    }
}
